//
//  MainViewController.m
//  InTime
//
//  Created by zhangjia on 15/9/8.
//  Copyright (c) 2015年 ClownYoJoy. All rights reserved.
//

#import "MainViewController.h"
#import "NewsListModel.h"

@interface MainViewController ()

@property (strong, nonatomic) NSMutableData *mData;//接收解析的数据

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self analysisData];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - 网络请求 & 数据解析

- (void)analysisData {
    //首页 数据
    //http://c.m.163.com/nc/article/headline/T1348647853363/0-140.html
    NSString *urlString = @"http://c.m.163.com/nc/article/headline/T1348647853363/0-140.html";
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
    [connection start];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    self.mData = [NSMutableData data];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [self.mData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:self.mData options:0 error:nil];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"请求失败,网络错误");
}

@end
